<?php
header('Content-Type:application/json;charset=UTF-8');
$conn = mysqli_connect('localhost','root','root','yuangong');
if(!$conn){
    echo json_encode([
        'code'=>0,
        'msg'=>'数据库连接失败'
    ]);
}
$sql = "select d.name,count(*)as total from yg y join bm d  on y.dept_id=d.id group by y.dept_id";
$query = mysqli_query($conn,$sql);
$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
$xData = [];
$yData = [];
foreach($result as $val){
    array_push($xData,$val['name']);
    array_push($yData,$val['total']);
}
echo json_encode([
    'code'=>1,
    'msg'=>'员工部门分布',
    'data' => [
    'xData' => $xData,
    'yData' => $yData,
        ]
]);
